package com.zlm.unsafe;

import java.util.HashSet;
import java.util.UUID;

/**
 * @Author: 郑
 *  ConcurrentModificationException 并发修改异常
 */
public class SetTest {
    public static void main(String[] args) {
        HashSet<String> set = new HashSet<>();
        //Set<String> set = Collections.synchronizedSet(new HashSet<>());
        //Set<String> set = new CopyOnWriteArraySet<>();
        for (int i = 0; i < 50; i++) {
            new Thread(() ->{
                set.add(UUID.randomUUID().toString().substring(0,6));
                System.out.println(set);
            }).start();
        }
    }
}
